<template>
  <div>
    <iframe
      v-if="externalUrl"
      ref="externalEmbed"
      :src="externalUrl"
      frameborder="0"
      style="width:100%;"
    ></iframe>
    <el-empty
      v-else
      :image-size="200"
      description="未配置外部页面地址"
    />
  </div>
</template>

<script>
import main from "./mixins/main";
import baseForm from "@admin/packages/table-operate/src/baseForm";
import Cookies from 'js-cookie'
export default {
  name: "Tem1170",
  extends: baseForm,
  mixins: [main],
  data() {
    return {
      listLoadingDia: false,
    };
  },
  computed: {
    externalUrl: function () {
      let customParam = this.pageInfo.customParam;
      if (customParam) {
        customParam = JSON.parse(customParam);
        if(customParam.url){
          var ssoToken = Cookies.get('SSO-Token');
          if(ssoToken){
            if(customParam.url.indexOf('?') > -1){
              return customParam.url + '&token=' + ssoToken
            }else{
              return customParam.url + '?token=' + ssoToken
            }
          }else{
            return customParam.url
          }
        } else {
          return "";
        }
      } else {
        return "";
      }
    },
  },
  mounted: function () {
    this.setIframeHeight()
    // 监听窗口大小变化，获取高度
    window.addEventListener('resize',this.setIframeHeight)
  },
  beforeDestroy() {
    window.removeEventListener('resize',this.setIframeHeight)
  },
  methods: {
    setIframeHeight() {
      let height = document.documentElement.clientHeight;
      height = height - 120
      console.log(height);
      this.$refs.externalEmbed.style.height = height + "px";
    },
  },
};
</script>
<style lang="scss" scoped>
</style>
